#include "DS18B20.h"

bit Start18B20()
{
	bit ack = 0;
	//1、初始化
	ack = OneWireRst();
	if (ack == 0)
	{
		//2、ROM指令
		WriteOneWire(SKIP_ROM);
		//3、功能指令 启动温度转换
		WriteOneWire(CONVERT_T);
	}
	return ~ack;
}

bit Read18B20(int * temp)
{
	bit ack = 0;
	unsigned char MSB,LSB;
	//1、初始化
	ack = OneWireRst();
	if (0 == ack)
	{
		//2、ROM指令
		WriteOneWire(SKIP_ROM);
		//3、功能指令 读取温度转换结果
		WriteOneWire(READ_REGISTER);
		//4、读转换结果 根据功能指令来确定
		LSB = ReadOneWire();
		MSB = ReadOneWire();
		*temp = ((int)MSB << 8) + LSB;
	}
	return ~ack;
	
}